<?php
require 'config/database.php';
require 'includes/functions.php';

echo "数据库连接测试...\n";
try {
    // 检查总轮次数
    $stmt = $pdo->query('SELECT COUNT(*) as total_rounds FROM game_rounds');
    $result = $stmt->fetch();
    echo "总轮次数: " . $result['total_rounds'] . "\n";
    
    // 检查最近10天的轮次分布
    $stmt = $pdo->query('SELECT DATE(start_time) as date, COUNT(*) as rounds FROM game_rounds GROUP BY DATE(start_time) ORDER BY date DESC LIMIT 10');
    echo "最近10天的轮次分布:\n";
    while($row = $stmt->fetch()) {
        echo $row['date'] . ": " . $row['rounds'] . "轮\n";
    }
    
    // 检查今天的轮次
    $stmt = $pdo->query('SELECT COUNT(*) as today_rounds FROM game_rounds WHERE DATE(start_time) = CURDATE()');
    $result = $stmt->fetch();
    echo "今天的轮次数: " . $result['today_rounds'] . "\n";
    
    // 检查最近几天的轮次详情
    $stmt = $pdo->query('SELECT id, round_number, DATE(start_time) as date, start_time FROM game_rounds ORDER BY start_time DESC LIMIT 20');
    echo "最近20轮详情:\n";
    while($row = $stmt->fetch()) {
        echo "ID: " . $row['id'] . ", 轮次: " . $row['round_number'] . ", 日期: " . $row['date'] . ", 时间: " . $row['start_time'] . "\n";
    }
    
} catch(Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
}
?>
